require 'time'
require 'socket'
class PlayState
	attr_accessor :time
	def initialize(client, host, port, send = true)
		if(send)
			sock = TCPSocket.new(host, port)
			name = client.name
			sock.puts("<pause client=\"#{name}\"/>")
			sock.close()
		end
		@time = 0
	end

	def button_clicked()
	end
end

class PauseState
	attr_accessor :time
	def initialize(client, host, port, send = true)
		if(send)
			sock = TCPSocket.new(host, port)
			name = client.name
			sock.puts("<pause client=\"#{name}\"/>")
			sock.close()
		end
		@start = Time.new
	end
	
	def button_clicked()
		stop = Time.new
		@time = stop - @start
		@start = Time.new
	end
end

class Pause
	def initialize(client, host, port)
		@client = client
		@host = host
		@port = port

		@pause_time = 0
		@state = PlayState.new(client, host, port, false)
	end

	def button_clicked()
		@state.button_clicked()
		@pause_time += @state.time
		if(@state.class == PauseState)
			@state = PlayState.new(@client, @host, @port)
		else
			@state = PauseState.new(@client, @host, @port)
		end
	end

	def is_paused()
		if(@state.class == PauseState)
			return true
		end
		return false
	end

	def pause_time
		@state.button_clicked()
		@pause_time += @state.time
		@state.time = 0
		return @pause_time
	end
end

